import type { FTP, SQL, Store } from '@/views/Connection/types';
import axios from 'axios';
import type { IResponse } from './types';

type LabelValue = {
  label: string;
  value: string;
  children?: LabelValue[];
  selectable?: boolean;
};
/* 
database(数据库接口),scale(秤接口),api(api接口)
*/
export const fetchOptions = (type: 'database' | 'scale' | 'api' | string) =>
  axios.get<IResponse<LabelValue[]>>(`/dataType/${type}`, {
    params: {
      type,
    },
  });
interface DataToBeMatched {
  origin: string;
  target: string;
}

type IDataConfig = {
  dataType: string;
} & SQL;
export const dataConfig = (data: IDataConfig) =>
  axios.post<IResponse<DataToBeMatched[]>>(`/dataConfig`, data);

export const apiConfig = (apiType: string) =>
  axios.get<
    IResponse<{
      data: SQL;
    }>
  >(`/apiConfig/${apiType}`);

interface IStoreResponse {
  sunlux: string;
}

export const fieldConfig = (data: DataToBeMatched[]) =>
  axios.post<IResponse<IStoreResponse>>('/fieldConfig', data);

export const accountConfig = (data: Store) => axios.post<IResponse>('/accountConfig', data);

export const getToken = (data: Store) => axios.post<IResponse>('/getToken', data);

export const postFTPConfig = (data: FTP) => axios.post<IResponse>('/dataFTPConfig', data);

export const apiChengConfig = (type: string) => axios.get<IResponse>(`/apiChengConfig/${type}`);

export const apiFileConfig = (type: string) => axios.post('/api/apiFileConfig');
